#include <iostream>
using namespace std;

const int N = 1e4 + 10;
int sum[N];
int f[N], g[N];
int main() {
    int n;
    cin >> n;
    int temp = n;
    while (temp--) {
        int x;
        cin >> x;
        sum[x] += x;
    }
    for (int i = 1; i < N; i++) {
        f[i] = g[i - 1] + sum[i];
        g[i] = max(g[i - 1], f[i - 1]);
    }
    int ret = max(f[N - 1], g[N - 1]);
    cout << ret << endl;
    return 0;
}